package com.hll.erp.util;

import com.hll.erp.entity.User;

import java.util.*;

/**
 * 返回用户权限集合
 *
 * @author Mr.Hu
 * @since 2021-07-05 14:30
 */
public class UserRoleUtils {
  private static final List<String> roleList =
      new ArrayList<>(Arrays.asList("buyer", "product", "seller", "sell_watch", "admin"));

  public static Set<String> getRoles(User user) {
    Set<String> roles = new HashSet<>();
    if (user.getCaigou()) roles.add(roleList.get(0));
    if (user.getCangku()) roles.add(roleList.get(1));
    if (user.getXiaoshou()) roles.add(roleList.get(2));
    if (user.getLingshou()) roles.add(roleList.get(3));
    if (user.getGuanli()) roles.addAll(roleList);
    return roles;
  }
}
